﻿using System;
using System.Text;
using System.Web;

using Bpms.Entity;
using Bpms.Common;

namespace Bpms.Bll
{
    /// <summary>
    /// 栏目类型
    /// </summary>
    public enum ColumnType
    {
        UserManagement = 1,
        CustomerManagement,
        ProjectManagement,
        PoManagement,
        StatisticsManagement,
        GlobalManagement
    }

    public class Global
    {

        /// <summary>
        /// 写bpms cookies
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="expires">cookie有效期</param>
        public static void WriteUserCookie(UserInfo userInfo, int expires)
        {
            if (userInfo == null)
            {
                return;
            }

            HttpCookie cookie = new HttpCookie("bpms");
            cookie.Values["userid"] = userInfo.UserID.ToString();
            cookie.Values["email"] = userInfo.Email;
            //cookie.Values["role"] =
            if (expires > 0)
            {
                cookie.Expires = DateTime.Now.AddMinutes(expires);
            }
            HttpContext.Current.Response.AppendCookie(cookie);
        }

        /// <summary>
        /// 获得bpms cookie值
        /// </summary>
        /// <param name="name">项</param>
        /// <returns>值</returns>
        public static string GetCookie(string name)
        {
            if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["bpms"] != null && HttpContext.Current.Request.Cookies["bpms"][name] != null)
            {
                return Security.UrlDecode(HttpContext.Current.Request.Cookies["bpms"][name].ToString());
            }

            return "";
        }
    }
}
